<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="../common.jsp"%>
<%@ page import="java.net.*,org.springside.core.Constants,cn.firstsoft.firstframe.admin.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%
int error_code = 0;
String id = request.getParameter("id");
String dbtype = request.getParameter("dbtype");
String maindir = request.getParameter("maindir");

if (id != null && !"".equals(id) 
	&& dbtype != null && !"".equals(dbtype)
	&& maindir != null && !"".equals(maindir)) {
	if ("sqlserver".equals(dbtype)) {
		if (!PropertyFile.writeProperties("jdbc.properties", "hibernate.dialect", "org.hibernate.dialect.SQLServerDialect")) {
			error_code = 2;
		}
	} else if ("oracle".equals(dbtype)) {
		if (!PropertyFile.writeProperties("jdbc.properties", "hibernate.dialect", "org.hibernate.dialect.Oracle9Dialect")) {
			error_code = 2;
		}
	}
	//修改主要路径 constant.main_storage_dir
	String constant_main_storage_dir = URLDecoder.decode(maindir, "utf-8");
	if (!PropertyFile.writeProperties("firstframe.properties", "constant.main_storage_dir", constant_main_storage_dir)) {
		error_code = 3;
	}	
	
	//判断是TOMCAT，还是APUSIC
	//Tomcat 需要 java:comp/env/
	
	String jndi_default_name = "jdbc/" + id;
	if ("TOMCAT".equals(Environment.getWebServerName())) 
		jndi_default_name = "java:comp/env/" + jndi_default_name;
		
	if (!PropertyFile.writeProperties("jdbc.properties", "jndi.default_name", jndi_default_name)) {
		error_code = 4;
	}
	
} else {
	error_code = 1;
}
%>
<html>
<head>
<title>管理控制台 - 数据中心</title>
<%@ include file="/common/meta2.jsp"%>
<link href="../style.css" type="text/css" rel=stylesheet>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%">
  <tr>
  	<td width="100%">
  		<% if (error_code > 0) { %>
  		数据中心启用错误，错误编号：<%=error_code %>，<a href="index.jsp">点这里返回数据中心列表</a>
  		<% } else { %>
  		新数据中心启用成功！生效必须重新启动服务器！<a href="index.jsp">点这里返回数据中心列表</a>
  		<% } %>
  	</td>
  </tr>
</table>
</body>
</html>
